const Vector = @import("vector.zig").Vector;


pub const PipeType = enum(u8) {
	HORIZONTAL,
	VERTICAL,
	CORNER_1,
	CORNER_2,
	CORNER_3,
	CORNER_4,
	END_1,
	END_2,
	END_3,
	END_4,
};


pub const Pipe = struct {
	x: u8,
	y: u8,
	type: PipeType,


	// Edge case: if the pipe is at the edge of the grid it may return its
	//   current position
	pub fn get_connections(self: *const Pipe) [4]?Vector {
		return switch (self.type) {
			PipeType.HORIZONTAL => .{
				Vector{.x = self.x -| 1, .y = self.y},
				Vector{.x = self.x +| 1, .y = self.y},
				null, // nulls in case pipes with more connections are added
				null,
			},
			PipeType.VERTICAL => .{
				Vector{.x = self.x, .y = self.y -| 1},
				Vector{.x = self.x, .y = self.y +| 1},
				null,
				null,
			},
			PipeType.CORNER_1 => .{
				Vector{.x = self.x +| 1, .y = self.y},
				Vector{.x = self.x, .y = self.y +| 1},
				null,
				null,
			},
			PipeType.CORNER_2 => .{
				Vector{.x = self.x -| 1, .y = self.y},
				Vector{.x = self.x, .y = self.y +| 1},
				null,
				null,
			},
			PipeType.CORNER_3 => .{
				Vector{.x = self.x -| 1, .y = self.y},
				Vector{.x = self.x, .y = self.y -| 1},
				null,
				null,
			},
			PipeType.CORNER_4 => .{
				Vector{.x = self.x +| 1, .y = self.y},
				Vector{.x = self.x, .y = self.y -| 1},
				null,
				null,
			},
			PipeType.END_1 => .{
				Vector{.x = self.x +| 1, .y = self.y},
				null,
				null,
				null,
			},
			PipeType.END_2 => .{
				Vector{.x = self.x, .y = self.y +| 1},
				null,
				null,
				null,
			},
			PipeType.END_3 => .{
				Vector{.x = self.x -| 1, .y = self.y},
				null,
				null,
				null,
			},
			PipeType.END_4 => .{
				Vector{.x = self.x, .y = self.y -| 1},
				null,
				null,
				null,
			},
		};
	}


	pub fn is_end(self: *const Pipe) bool {
		return switch (self.type) {
			PipeType.END_1,
			PipeType.END_2,
			PipeType.END_3,
			PipeType.END_4 => return true,
			else => return false,
		};
	}
};
